Skip to content

Restrict permissions on disk token cache - #866

Open
hadley wants to merge 2 commits into
mainfrom
harden-token-cache-perms
Open

Restrict permissions on disk token cache#866
hadley wants to merge 2 commits into
mainfrom
harden-token-cache-perms

Conversation

@hadley

@hadley hadley commented Jul 25, 2026

Copy link
Copy Markdown
Member

The on-disk OAuth token cache was created with default permissions: directories at 755 and token files at 644 (subject to umask), so cached tokens were readable by other local users. Since the "encryption" of these files uses a key shipped inside the package, file permissions are the real line of defense on multi-user machines.

This PR:

  • Creates the cache directory with mode 0700, and re-applies that mode on each use so directories created by earlier versions of httr2 are also fixed up.
  • Chmods each token file to 0600 after writing, matching the hardening secret_decrypt_file() already applies.

Both changes are no-ops on Windows, where these modes don't apply; the new test is skipped there.

🤖 Generated with Claude Code

hadley added 2 commits July 25, 2026 08:21
The OAuth disk cache directory was created with default permissions
(typically 755) and token files were written with the default 644, so
cached tokens were readable by other users on the same machine. Now
create the cache directory with mode `0700` (and re-apply it to
directories created by earlier versions) and chmod token files to
`0600` after writing.
Move `skip_on_os("windows")` after the set/get round-trip so that the
`Sys.chmod()` calls are exercised on Windows too; only the mode
assertions are skipped there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant